package com.example.lib;
/**
 * 鸭子抽象类
 * */
public abstract class Duck {
    FlyBehavior flyBehavior;
    QuackBehavior quackBehavior;

    //行为动态设置
    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior=flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

   public abstract void display();   //不同鸭子长相不同
    //行为委托给具体的行为类处理
    public void performFly()
    {
        flyBehavior.fly();
    }

    public void performQuack() {
        quackBehavior.quack();
    }

    public void swim() {//所有的鸭子都会浮水
        System.out.println("All ducks float,even decoys!");
    }
}